/**
 * Copyright 2018 asiainfo Inc.
 **/
package com.myz.app.shiro.factory;

import com.myz.app.shiro.listener.ShiroSessionListener;
import com.myz.app.shiro.session.ShiroSession;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author maoyz on 2018/6/11
 * @version: v1.0
 */
public class ShiroSessionFactory implements SessionFactory {

  private final Logger logger = LoggerFactory.getLogger(ShiroSessionListener.class);

  /**
   * @param initData
   * @return
   */
  @Override
  public Session createSession(SessionContext initData) {
    logger.debug("++++++++++++++++++ ShiroSessionFactory ");

    if (initData != null) {
      String host = initData.getHost();
      if (host != null) {
        return new ShiroSession(host);
      }
    }

    return new ShiroSession();
  }
}
